package com.beta.admin.controller;

import com.beta.admin.support.web.BaseController;
import com.beta.admin.vo.AdminVo;
import com.beta.common.web.ContentType;
import com.beta.dto.admin.MenuDto;
import com.beta.service.IMenusService;
import com.beta.entity.Admins;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Created by vector on 2016/12/29.
 */
@RestController()
@RequestMapping(value = RequestMappingConstants.MAPPING_PREFIX + "/system")
public class SystemController extends BaseController {

    @Autowired
    private IMenusService menusService;
    @Autowired
    private MapperFacade beanMapper;

    @GetMapping(value = "/menus", produces = {ContentType.JSON})
    public Object getMenus() {
        List<MenuDto> menus = menusService.getAdminMenus(getCurrentAdmin().getId());
        return ok(menus);
    }

    @GetMapping(value = "/menus/actions", produces = {ContentType.JSON})
    public Object getMenuActions() {
        Map<String, String> adminMenuActionsMap = menusService.getAdminMenuActionsMap(getCurrentAdmin().getId());
        return ok(adminMenuActionsMap);
    }

    @GetMapping(value = "/user", produces = {ContentType.JSON})
    public Object getCurrentUser() {
        Admins currentAdmin = super.getCurrentAdmin();
        AdminVo adminVo = beanMapper.map(currentAdmin, AdminVo.class);
        return ok(adminVo);
    }

}
